<%@ page language="java" contentType="text/html; charset=utf-8"%>
<html>
<head>
<%@ include file="/extjs/include/all.jsp"%>
<link
	href="${pageContext.request.contextPath}/edu.ccut.saturn.manager.dict.impl/extpageModule/page/css/dict.css"
	rel="stylesheet" type="text/css">
<title>添加数据字典项</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/edu.ccut.saturn.manager.dict.impl/extpageModule/page/js/dictValidate.js">
</script>
</head>
<body>
</body>
</html>

<script type="text/javascript">
Ext.onReady(function(){

	Ext.QuickTips.init();  
//	function getDictTypeResult(){		       	
//		Ext.get("type").dom.value = '<%=request.getParameter("key")%>';
 //   }
    //------------------------------------------------------------------------
	//添加用户的表单
	//
	//
	//--------------------------------------------------------------------------
	var addDictParam = new Ext.FormPanel({
	    labelWidth: 100,
	    url:'${pageContext.request.contextPath}/edu.ccut.saturn.manager.dict.impl::/extDictParamModule/action/AddDictParam.action',
	    id:'addDictParam',
	    frame:true,
	    title: '添加字典项',
	    bodyStyle:'padding:5px 5px 0',
	    width: 350,
	    defaults: {width: 200},
	    defaultType: 'textfield',
	    items: [{
	            fieldLabel: '数据字典项',
	            name: 'code',
	            id: 'code',
	            allowBlank:false,
	            blankText:'不能为空',
	            vtype: 'isNumberAlphaUnderline'
	        },{
	            fieldLabel: '字典项名称',
	            name: 'value',
	            id: 'value',
	            allowBlank:false,
	            blankText:'姓名不能为空',
	            vtype: 'isNumberAlphaUnderlineChinese'
	        } ,{
	            fieldLabel: '字典项拼音',
	            name: 'py',
	            id: 'py',
	            allowBlank:false,
	            blankText:'拼音不能为空',
	            vtype: 'isAlpha'
	        }
	    ]
	});
	
	//--------------------------------------------------------------------------------------------
	//						添加用户
	//
	//--------------------------------------------------------------------------------------------
			
	if(!win){
         var win = new Ext.Window({
            layout      : 'fit',
            width       : 400,
            height      : 200,
            plain       : true,
            animEl: 'result',
            closable: false,
            items: [addDictParam],
            buttons: [{
               text     : '添加',
               handler  : function(){
                   	if(addDictParam.form.isValid()){
                   		addDictParam.form.submit({
	                		url: '${pageContext.request.contextPath}/edu.ccut.saturn.manager.dict.impl::/extDictParamModule/action/AddDictParam.action', 
	                		success : function(form, action) {
	                			var myResult = Ext.util.JSON.decode(action.response.responseText);
	                			if (myResult.addSucc == 'true') {
	                					Ext.MessageBox.show({
	                				 		title: '添加成功',
		                                    msg: '恭喜您，添加字典项成功！',
		                                    width:200,
		                                    buttons: Ext.MessageBox.OK,
		                                    fn: function(btn) {
										         window.location = '${pageContext.request.contextPath}/edu.ccut.saturn.manager.dict.impl/extpageModule/paramPage/dictParamList.jsp?key=<%=request.getParameter("key")%>';
										    }
		                                 });                                    
	                            } else {
		                            	Ext.MessageBox.show({
		                                    title: '添加失败',
		                                    msg: '对不起，添加字典项失败！字典项可能已经存在或者与数据库连接发生了错误！',
		                                    buttons: Ext.MessageBox.OK,
		                                    icon: Ext.MessageBox.ERROR
	                                	});
	                            }
	                        },
	                        failure : function(form, action) {
	                        	
	                        	Ext.MessageBox.show({
                                    title: '添加失败',
                                    msg: '对不起，添加失败！',
                                    buttons: Ext.MessageBox.OK,
                                    icon: Ext.MessageBox.ERROR
                                });
	                        },
	                        params:{
	                        	key:'<%=request.getParameter("key")%>'
	                        },
	                		waitMsg:'正在添加字典项，请稍后...'
                		});
                   	} else {
                   		Ext.MessageBox.alert('警告','对不起，您的信息有误！')
                   	}
                 }
            },{
                text     : '返回',
                handler  : function(){
                	window.history.back();
                    win.hide();
                    }
           },{
                text     : '重置',
                handler  : function(){
                    addDictParam.form.reset(); 
                }
            }]
        });
    }
    win.show();
});
</script>